package org.NooLab.glue.net.http.rest.resources;




import org.restlet.representation.Representation;
import org.restlet.resource.Delete;
import org.restlet.resource.Post;
import org.restlet.resource.Put;

  

/*
 *  if there would be any, we would return the virtual "location" of the resource
 *  
 *  - SOURCE : either for posting data
 *  - SOURCE : for receiving notifications
 *  - RECEPTOR : for downloading data
 *  - RECEPTOR : for downloading control requests
 *  
 */


/**
 * 
 * we need information of the level of the server (beyond the particular accepting process)
 * in order to block requests from the same client, probably using the transaction secret ...
 *
 */
public class RegistrationsResource  extends BaseResource{
	
	String role="" ;
	
	public RegistrationsResource(){
	
	}
	
	@Delete
	public String RegPost(Representation entity){
		// used e.g. for saying "I am alive, do you have some news for me?"
		String responseResult="" ; 
	
		role = getRegistrationTarget();
		// read the id of the client
		responseResult = "bye, bye."; //"no new offers for you" ; 

		
		return responseResult;
	}
	



	@Put
	public String DataHandlerRegPut(Representation entity){

												// System.out.println("Restlet-Server (1), DataHandlerRegPut() ...");
		String msgText="" ;
		MessageSupply msgSupply;
		
												out.print(3,"Restlet-Server (1), DataHandlerRegPut() -> Request : \n"+ getUri() );
		
		role = getRegistrationTarget();
		msgSupply = prepareMessageRouting();

		try {
			
												out.printErr(3,"Restlet-Server (1), DataHandlerRegPut() -> object = : "+this.toString() );
			
			msgText = entity.getText();
		
			
		} catch (Exception e) {
			e.printStackTrace();
		}

		// this will also remove again the observer for this resource process
		serveAndGetReturn( msgSupply, msgText);
		
		getResponse().commit();
		responseSlot=null;
												out.print(3,"returning new registration (len = "+regResult.length()+" chars)...");
												out.print(5,"regResult is...      "+regResult);
		return regResult;
		
	}
 
	
	@Post
	public String DataHandlerUnRegDel(Representation entity){

												// System.out.println("Restlet-Server (1), DataHandlerRegPut() ...");
		String msgText="" ;
		MessageSupply msgSupply;
		
												out.print(3,"Restlet-Server (1), DataHandlerUnRegDel() -> Request : \n"+ getUri() );
		
		role = getRegistrationTarget();
		msgSupply = prepareMessageRouting();

		try {
			
												out.printErr(3,"Restlet-Server (1), DataHandlerUnRegDel() -> object = : "+this.toString() );
			
			msgText = entity.getText();
		
			
		} catch (Exception e) {
			e.printStackTrace();
		}

		serveAndGetReturn( msgSupply, msgText,1);
		
		getResponse().commit();
												
		regResult = "" ;
		return regResult;
		
	}
 
}



















